package com.woniuxy.controller;

import com.woniuxy.entity.ShopSpecOptions;
import com.woniuxy.service.ShopSpecOptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import com.woniuxy.utils.ResponseResult;

import java.util.List;


/**
 * (ShopSpecOptions)表控制层
 *
 * @author makejava
 * @since 2025-07-15 14:13:33
 */
@RestController
@RequestMapping("shopSpecOptions")
public class ShopSpecOptionsController {

    /**
     * 服务对象
     */
    @Autowired
    private ShopSpecOptionsService shopSpecOptionsService;

    /** 通过specId查询所有*/
    @GetMapping("/opt/{id}")
    public ResponseResult<List<ShopSpecOptions>> findById(@PathVariable("id") Integer specId) {
        return ResponseResult.success(shopSpecOptionsService.findById(specId));
    }

    /**
     * 分页查询
     *
     * @param shopSpecOptions 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseResult<Page<ShopSpecOptions>> queryByPage(ShopSpecOptions shopSpecOptions, PageRequest pageRequest) {
        return ResponseResult.success(this.shopSpecOptionsService.queryByPage(shopSpecOptions, pageRequest));
    }

    /**
     * 通过主键查询多条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<ShopSpecOptions> queryById(@PathVariable("id") Integer id) {
        return ResponseResult.success(this.shopSpecOptionsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param shopSpecOptions 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseResult<ShopSpecOptions> add(ShopSpecOptions shopSpecOptions) {
        return ResponseResult.success(this.shopSpecOptionsService.insert(shopSpecOptions));
    }

    /**
     * 编辑数据
     *
     * @param shopSpecOptions 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseResult<ShopSpecOptions> edit(ShopSpecOptions shopSpecOptions) {
        return ResponseResult.success(this.shopSpecOptionsService.update(shopSpecOptions));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseResult<Boolean> deleteById(Integer id) {
        return ResponseResult.success(this.shopSpecOptionsService.deleteById(id));
    }

}

